package com.nondo.rdp.finance.repository.course;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.finance.domain.course.StageCourse;

public interface StageCourseRepository extends JpaRepository<StageCourse, Long>, JpaSpecificationExecutor<StageCourse> {
    @Query("select a from StageCourse a where a.id=:id and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    Optional<StageCourse> findOne(@Param("id") int id);

    @Modifying
    @Query("update StageCourse set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    void deleteById(Long id);

    StageCourse save(StageCourse hotSearch);

    @Query("select a from StageCourse a where a.type=:type and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
	List<StageCourse> findAll(@Param("type") int type);

    @Query("select a from StageCourse a where a.course.id=:cid and a.type=:type and delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
	StageCourse getOne(@Param("cid") Long cid, @Param("type") int type);

}
